package com.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.entity.NewOwner;
import com.service.NewOwnerService;
@Controller
@RequestMapping("/owner")
public class NewOwnerController {
	
	@Resource
	NewOwnerService newOwnerService;
	
	@ResponseBody
	@RequestMapping(value="/add",produces = "text/html;charset=UTF-8",method=RequestMethod.POST)
	public String insert(HttpServletRequest request,NewOwner newOwner){
		String openid=request.getParameter("openid");
		String phone=request.getParameter("phone");
		newOwner.setOpenid(openid);
		newOwner.setPhone(phone);
		int num=newOwnerService.insert(newOwner);
		if(num==1){
			System.out.println("添加成功");
			return "";
		}else{
			System.out.println("添加失败");
			return "";
		}
	}
	@ResponseBody
	@RequestMapping(value="/select",produces = "text/html;charset=UTF-8",method=RequestMethod.GET)
	public String select(HttpServletRequest request,ModelMap map){
		//String openid=request.getParameter("openid");
		NewOwner newOwner=newOwnerService.select("oV3MK0SKeHnmjhNYVDE1A-ercznk");
		if(newOwner!=null){
			map.addAttribute("list", newOwner);
			new JSONObject();
			JSONObject json=JSONObject.fromObject(map);
			System.out.println(json);
			return json.toString();
		}else{
			System.out.println("没有数据");
			return "";
		}
	}
}
